<template>
  <div>
    <el-form :model="form" :rules="rules" ref="form">
   
         <el-form-item label="学生" prop="studentId" label-width="90px">
        <el-select v-model="form.studentId" placeholder="请选择学生">
          <el-option v-for="item in studentlist" :label="item.name" :value="item.id" :key="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="课程" prop="courseId" label-width="90px">
        <el-select v-model="form.courseId" placeholder="请选择课程">
          <el-option v-for="item in courselist" :label="item.name" :value="item.id" :key="item.id"></el-option>
        </el-select>
      </el-form-item>
         <el-form-item label="日常得分" label-width="90px" prop="name">
        <el-input v-model="form.dailyScore" autocomplete="off"></el-input>
      </el-form-item>
         <el-form-item label="考试得分" label-width="90px" prop="name">
        <el-input v-model="form.examScore" autocomplete="off"></el-input>
      </el-form-item>
         <el-form-item label="总分" label-width="90px" prop="name">
        <el-input v-model="form.score" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item style="display: flex; justify-content: flex-end">
        <el-button type="primary" @click="submit">确定</el-button>
        <el-button @click="qx">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { courseadd } from '@/api/select';
import { studentnames } from '@/api/select';
import { coursenames } from '@/api/select';
export default {
  data () {
    return {
      form: {
        id: -1,
        courseId:"",
        dailyScore:"",
        examScore:"",
        score:"",
        studentId:""
        
      },
      courselist:[],
      studentlist:[],
      rules: {
        studentId: [
          {
            required: true,
            message: '请选择学生',
            trigger: 'blur'
          }
        ],
         courseId: [
          {
            required: true,
            message: '请选择课程',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  methods: {
    submit () {
    //   触发表单验证
      this.$refs['form'].validate(falg => {
        if (falg) {
         courseadd(this.form).then(res => {
            if (res.code === 0) {
              this.$message({
                type: 'success',
                message: '添加成功'
              })
              // 通知父级关闭对话框
              this.$emit('close')
            }
          })
        }
      })
    
    },
    getlist(){
        studentnames().then(res=>{
            this.studentlist=res.data
        })
        coursenames().then(res=>{
            this.courselist=res.data
        })
    },
    qx(){
       // 通知父级关闭对话框
    this.$emit('close')
    }
    
  },
  mounted(){
    this.getlist()
  }
}
</script>

<style lang="sass" scoped></style>
